import { Company } from '../../model/company-model.js';

var company  = new Company();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    wx.setNavigationBarTitle({
      title: '我的评论管理',
    })

    that.initpage();
 

  },

  initpage:function()
  {
    var that = this;

    var params = {page:that.data.page};

    company.getMyComment((data) => {

   
      that.setData({

        commentlist:data.commentlist
      });

      wx.hideNavigationBarLoading(); //完成停止加载
      wx.stopPullDownRefresh();


  },params);


  },

  delComment:function(e)
  {
    
    var that = this;

    var id = e.currentTarget.dataset.id;
    var params = {id:id};
    wx.showModal({
      title: '提示',
      content: '确定删除该条评论？',
      success: function (res) {
        if (res.confirm) {

            company.delComment((data) => {

              if(data.status == 0 )
              {
                wx.showModal({
                  title: '提示',
                  content: data.msg,
                  showCancel: false,
                  success:function(){

                    that.onLoad();
                  }
                })

            

              }else{

                wx.showToast({
                  title: data.msg,
                  icon: 'none',
                  duration: 2000
                })

              }
                                        
                },params);


        }
      }

    })

  },

  toSetComment: function (e) {
    var id = e.currentTarget.dataset.id;

      wx.navigateTo({
        url: "/pages/setcomment/index?id=" + id
      })
  

  },

  toJob: function (e) {
    var pid = e.currentTarget.dataset.id;

      wx.navigateTo({
        url: "/pages/jobdetail/index?id=" + pid
      })
  

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    this.initpage();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
  
    this.data.page = this.data.page+1;
    that.initpage();

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    return {
        title:'我的评论管理' ,
        path: '/pages/mycomment/index'
    }
  }
})